package com.neusoft.chenanqi.controller;

import javax.inject.Inject;

import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import com.fasterxml.jackson.databind.node.ObjectNode;
import com.neusoft.chenanqi.dto.EmpSalDto;
import com.neusoft.chenanqi.service.FixedSalService;
import com.zero.basic.exception.SmsErrorConstant;
import com.zero.basic.exception.SmsRuntimeException;
import com.zero.basic.exception.SmsStatusCode;
import com.zero.basic.model.Pager;
import com.zero.basic.util.JsonCreator;

@Controller("fixedSalaryController")
@RequestMapping("fixedSalary")
public class FixedSalaryController {
	
	@Inject
	private FixedSalService fixedSalService;

	@RequestMapping("/searchFixedSal")
	@ResponseBody
	public Object searchSal(String depName, String empNo, String month,
			String salFrom, String salTo) {
		ObjectNode objectNode = JsonCreator.generateJsonObj();

		try {
			Pager<EmpSalDto> empSalDtoPager = fixedSalService.listFixedSal(depName, empNo, month, salFrom, salTo);
			objectNode.putPOJO("response", empSalDtoPager);
			objectNode.put("message", "获取固定工资列表成功");
			objectNode.put("statusCode", SmsStatusCode.SUC_CODE);
		} catch (SmsRuntimeException e) {
			objectNode.put("message", e.getErrorDescription());
			objectNode.put("error", e.getError());
			objectNode.put("statusCode", e.getStatusCode());
		} catch (Exception e) {
			e.printStackTrace();
			objectNode.put("message", SmsErrorConstant.SERVER_ERROR_MSG);
			objectNode.put("error", SmsErrorConstant.WEB_APPLICATION);
			objectNode.put("statusCode", SmsStatusCode.SERVER_ERROR);
		}
		return objectNode;
	}
}
